package Log_in_test;


	import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
	
	public class LoginForm {
        private final WebDriver driver;
	    private By loginformLocator = By.id("form-login");
	    private By usernameLocator = By.id("modlgn_username");
	    private By passwordLocator = By.id("modlgn_passwd");
	    private By loginButtonLocator = By.name("Submit");
	   
	    public LoginForm(WebDriver driver) {
	        this.driver = driver;
	       
	        if (!driver.findElement(loginformLocator).isDisplayed()) {
	            throw new IllegalStateException("There is no login form");
	        }
	    }
	   
	    public LoginForm typeUsername(String username) {
	       
	        driver.findElement(usernameLocator).sendKeys(username);

	        return this;    
	    }
	   
	    public LoginForm typePassword(String password) {
	       
	        driver.findElement(passwordLocator).sendKeys(password);
	        return this;    
	    }
	   
	    public TrueLoggedInpage submitLogin() {
	       
	        driver.findElement(loginButtonLocator).submit();
	       
	        return new TrueLoggedInpage(driver);    
	    }
	   
	    public FalseLoginpage submitFalseLogin() {
	       
	        driver.findElement(loginButtonLocator).submit();
	        return new FalseLoginpage(driver);  
	    }

	    public TrueLoggedInpage loginAs(String username, String password) {
	        typeUsername(username);
	        typePassword(password);
	        return submitLogin();
	    }
	}


